package amartin47;

import java.awt.*;

import no.geosoft.cc.graphics.*;


public class TestObject extends GObject
{
  private GSegment  line_;
  private double[]  x_, y_;
  

  /**
   * As a rule of thumb we create as much of the object during
   * construction as possible. Try to do geometry only in the
   * draw method.
   */
  TestObject()
  {
    GStyle lineStyle = new GStyle();
    lineStyle.setLineWidth (2);      
    lineStyle.setForegroundColor (new Color (100, 100, 100));
    lineStyle.setAntialiased (true);

    GStyle symbolStyle = new GStyle();
    symbolStyle.setForegroundColor (new Color (0, 0, 255));

    GStyle textStyle = new GStyle();
    textStyle.setFont (new Font ("Dialog", Font.BOLD, 14));
    textStyle.setForegroundColor (new Color (255, 255, 0));
    textStyle.setBackgroundColor (new Color (100, 100, 100));      
    
    line_ = new GSegment();
    line_.setStyle (lineStyle);
    addSegment (line_);

    GImage symbol = new GImage (GImage.SYMBOL_SQUARE2);
    symbol.setStyle (symbolStyle);
    line_.setVertexImage (symbol);

    int nPoints = 10;
    
    for (int i = 0; i < nPoints; i++) {
      GText text = new GText ("Point " + i,
                              GPosition.NORTH |
                              GPosition.STATIC);
      text.setStyle (textStyle);
      line_.addText (text);
    }

    // Geometry
    x_ = new double[nPoints];
    y_ = new double[nPoints];

    for (int i = 0; i < nPoints; i++) {
      x_[i] = 0.2 + 0.8 * i * (1.0 / nPoints);
      y_[i] = 0.1 + 0.8 * Math.random();
    }
  }
  

  
  public void draw()
  {
    line_.setGeometry (x_, y_);
  }
}
